<template>
  <BaseControlTemplate
    :new-params="newParams"
    :page-view-mode="pageViewMode"
    :readonly="readonly"
    :model-value="modelValue"
    :validate-error="validateError"
    :save-dialog-config="saveDialogConfig"
  >
    <template>
      <div v-if="pageViewMode === 'print'" class="printDiv">
        {{
          newParams.data.filter((item) => {
            return item.id == modelValue2
          })[0].name
        }}
      </div>
      <el-select
        v-else
        v-model="modelValue2"
        :placeholder="newParams.placeholder"
        class="print_special"
      >
        <el-option
          v-for="item in newParams.data"
          :key="item.id"
          :label="item.name"
          :value="item.id"
          :disabled="pageViewMode !== 'runtime' || readonly"
        ></el-option>
      </el-select>
    </template>
  </BaseControlTemplate>
</template>

<script>
import mixins from "../../mixins/vue.js";
export default {
  name: "ControlSelect",
  mixins: [mixins],
  data() {
    return {
      newParams: {},
    };
  },
  created() {
    this.newParams = JSON.parse(JSON.stringify(this.params));
    this.newParams.value = this.newParams.value?.[0] || "";
  },
  methods: {
    validate() {
      if (this.pageViewMode === "runtime") {
        this.validateRequired();
        this.newParams.value = [this.modelValue2];
      }
      return {
        validateError: this.validateError,
        controlValue: this.newParams,
      };
    },
  },
};
</script>

